package com.dwj.auto.comment.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dwj.auto.comment.config.mybatis.plus.CommonServiceImpl;
import com.dwj.auto.comment.dao.entity.SubscribeUser;
import com.dwj.auto.comment.dao.mapper.SubscribeUserMapper;
import com.dwj.auto.comment.service.ISubscribeUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author dwjian
 * @since 2020-09-18
 */
@Service
public class SubscribeUserServiceImpl extends CommonServiceImpl<SubscribeUserMapper, SubscribeUser> implements ISubscribeUserService {

    @Override
    public SubscribeUser insertOrReSubscribe(SubscribeUser subscribeUser) {
        int i = baseMapper.insertOrReSubscribe(subscribeUser);
        if(i != 0){
            QueryWrapper<SubscribeUser> wrapper = new QueryWrapper();
            wrapper.lambda().eq(SubscribeUser::getOpenId, subscribeUser.getOpenId());
            wrapper.lambda().eq(SubscribeUser::getIsDel, 0);
            return baseMapper.selectOne(wrapper);
        }
        return null;
    }
}
